//
//  AppDelegate.m
//  ai2ban
//
//  Created by mac book pro on 2018/1/6.
//  Copyright © 2018年 mac book pro. All rights reserved.
//

#import "AppDelegate.h"
#import <IQKeyboardManager.h>
#import "TabBarController.h"
#import <AlipaySDK/AlipaySDK.h>

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    [self initIQKeyboardManager];
    [self initTheWindow];
    return YES;
}

-(void)initIQKeyboardManager{
    
    IQKeyboardManager *sharedIQKBManager = [IQKeyboardManager sharedManager];
    sharedIQKBManager.enable = YES;
    sharedIQKBManager.shouldResignOnTouchOutside = YES;
    sharedIQKBManager.shouldToolbarUsesTextFieldTintColor = YES;
    sharedIQKBManager.enableAutoToolbar = YES;
}

- (void)initTheWindow {
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    self.window.rootViewController = [[TabBarController alloc] init];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    if ([url.host isEqualToString:@"safepay"]) {
        //跳转支付宝钱包进行支付，处理支付结果
        [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
            NSInteger resultStatue = [resultDic[@"resultStatus"] integerValue];
            switch (resultStatue) {
                case 9000:
                    [MozTopAlertView showWithType:MozAlertTypeSuccess text:@"支付成功" parentView:nil];
                    break;
                case 8000:
                    [MozTopAlertView showWithType:MozAlertTypeError text:@"正在处理中" parentView:nil];
                    break;
                case 4000:
                    [MozTopAlertView showWithType:MozAlertTypeError text:@"订单支付失败" parentView:nil];
                    break;
                case 5000:
                    [MozTopAlertView showWithType:MozAlertTypeError text:@"重复请求" parentView:nil];
                    break;
                case 6001:
                    [MozTopAlertView showWithType:MozAlertTypeError text:@"用户中途取消" parentView:nil];
                    break;
                case 6002:
                    [MozTopAlertView showWithType:MozAlertTypeError text:@"网络连接出错" parentView:nil];
                    break;
                case 6004:
                    [MozTopAlertView showWithType:MozAlertTypeError text:@"支付结果未知" parentView:nil];
                    break;
                default:
                    break;
            }
        }];
    }
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
